/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} p
 * @param {TreeNode} q
 * @return {boolean}
 */
var inorderTraversal = function (root) {
  const res = []
  if (!root) {
    return res
  }
  const start = root => {
    if (root.left) {
      start(root.left)
    } else {
      res.push(root.left)
    }
    res.push(root.val)
    root.right ? start(root.right) : res.push(root.right)
  }
  start(root)
  return res
}

var isSameTree = function (p, q) {
  const parr = inorderTraversal(p)
  const qarr = inorderTraversal(q)
  console.log(parr)
  console.log(qarr)
  return parr.length === qarr.length && parr.every((item, index) => item === qarr[index])
}
